import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { CommonResponse } from '../../model';
import { ApiService, urlService } from '../api';
import { environment } from './../../../environments/environment';

export interface TokenData {
  loginId: string;
  token: string;
  image: string;
  isFundPwd: true;
}

@Injectable()
export class SignService {

  sign(data: { pwd: string } & ({ email: string } | { mobile: string })): Observable<CommonResponse<TokenData>> {
    const url = urlService(environment.type, '登入');
    return this.api.post<CommonResponse<TokenData>>(url, data);
  }

  signout(): Observable<CommonResponse<string>> {
    return this.api.post<CommonResponse<string>>(urlService(environment.type, '退出登录'));
  }

  error(error: any) {
    this.api.goToWhere(error);
  }

  constructor(private api: ApiService) { }
}
